import { ref, computed } from 'vue';

import { defineStore } from 'pinia';

export const useMapStore = defineStore('map', () => {
  //通过TopBar获取数据 经由pinia传递给Map组件
  const center = ref([]);
  const adCode = ref('');
  const getCenter = (val) => {
    center.value = val;
    console.log('pinia获取中心坐标成功', [center.value[0], center.value[1]]);
  };
  const getAdCode = (val) => {
    adCode.value = val;
    console.log('pinia获取adcode成功', adCode.value);
  };

  //添加两个状态管理
  const dataReady = ref(false);
  const domReady = ref(false);
  const initReady = computed(() => {
    return dataReady.value && domReady.value;
  });
  const setDataReady = (val) => {
    dataReady.value = val;
    console.log('TopBar组件数据获取完成', '等待初始化地图');
  };
  const setDomReady = (val) => {
    domReady.value = val;
    console.log('Map组件dom加载完成', '等待初始化地图');
  };

  //绘画模式
  const drawType = ref('Point');
  const setDrawType = (val) => {
    drawType.value = val;
    console.log('绘画类型切换了', drawType.value);
  };

  //标记模式
  const markType = ref('');
  const setMarkType = (val) => {
    markType.value = val;
    console.log('标记类型切换了', markType.value);
  };

  //zoom状态控制
  const zoom = ref('');
  const setZoom = (val) => {
    zoom.value = val;
    if (zoom.value >= '13') {
      console.log('可以添加标记了');
    }
  };
  return {
    center,
    adCode,
    getCenter,
    getAdCode,
    dataReady,
    domReady,
    initReady,
    setDataReady,
    setDomReady,
    drawType,
    setDrawType,
    markType,
    setMarkType,
    zoom,
    setZoom,
  };
});
